using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using System.Drawing.Imaging;

namespace BingDownloader
{
    partial class ImageForm : Form
    {
        System.Media.SoundPlayer _fadein = new System.Media.SoundPlayer(BingDownloader.Properties.Resources.Fadein);
        System.Media.SoundPlayer _fadeout = new System.Media.SoundPlayer(BingDownloader.Properties.Resources.Fadeout);        

        public ImageForm()
        {
            InitializeComponent();       
            _fadein.Play();
            timer1.Start();
        }

        #region Assembly Attribute Accessors

        public string AssemblyTitle
        {
            get
            {
                // Get all Title attributes on this assembly
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                // If there is at least one Title attribute
                if (attributes.Length > 0)
                {
                    // Select the first one
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    // If it is not an empty string, return it
                    if (titleAttribute.Title != "")
                        return titleAttribute.Title;
                }
                // If there was no Title attribute, or if the Title attribute was the empty string, return the .exe name
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public string AssemblyDescription
        {
            get
            {
                // Get all Description attributes on this assembly
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                // If there aren't any Description attributes, return an empty string
                if (attributes.Length == 0)
                    return "";
                // If there is a Description attribute, return its value
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public string AssemblyProduct
        {
            get
            {
                // Get all Product attributes on this assembly
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                // If there aren't any Product attributes, return an empty string
                if (attributes.Length == 0)
                    return "";
                // If there is a Product attribute, return its value
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public string AssemblyCopyright
        {
            get
            {
                // Get all Copyright attributes on this assembly
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                // If there aren't any Copyright attributes, return an empty string
                if (attributes.Length == 0)
                    return "";
                // If there is a Copyright attribute, return its value
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AssemblyCompany
        {
            get
            {
                // Get all Company attributes on this assembly
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                // If there aren't any Company attributes, return an empty string
                if (attributes.Length == 0)
                    return "";
                // If there is a Company attribute, return its value
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.Opacity > 0.8)
            {
                timer1.Stop();
            }
            else
            {
                this.Opacity += 0.1;
            }
        }
        protected override void WndProc(ref Message m)
        {
            const int WmNcHitTest = 0x84;
            const int WmNCDoubleClick = 0x00A3;
            const int HtClient = 1;
            const int HtCaption = 2;

            if (m.Msg == WmNCDoubleClick)
                m.Result = new IntPtr(HtClient);
            else if (m.Msg == WmNcHitTest)
                m.Result = new IntPtr(HtCaption);
            else
                base.WndProc(ref m);
        }
        private void ImageForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            _fadeout.Play();
            for (; this.Opacity > 0.1; )
            {
                this.Opacity -= 0.1;
                System.Threading.Thread.Sleep(25);
            }
        }

        private void buttonClose_MouseHover(object sender, EventArgs e)
        {
            buttonClose.Image = global::BingDownloader.Properties.Resources.closebright;
        }

        private void buttonClose_MouseLeave(object sender, EventArgs e)
        {
            buttonClose.Image = global::BingDownloader.Properties.Resources.closenormal;
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        } 
    }
}
